package com.jiangyao.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiangyao.common.ApiResult;
import com.jiangyao.model.dto.*;
import com.jiangyao.model.vo.*;
import com.jiangyao.service.SubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lijing
 * @create 2020/8/12
 */

@RestController
@RequestMapping("/subject")
@Api(tags = "课程相关接口")
public class SubjectController extends BaseController{

    @Autowired
    private SubjectService subjectService;

    @PostMapping("getSubjectInfo")
    @ApiOperation(value = "获取用户学习课程的信息")
    public ApiResult<SubjectVo> getSubjectInfo (@RequestBody SubjectDto subjectDto){
        return ApiResult.success(subjectService.getSubjectInfo(subjectDto));
    }


    @PostMapping("getDirectory")
    @ApiOperation(value="获取当前用户学习的课程目录完成情况")
    public ApiResult<SChapterVo> getDirectory(@RequestBody SubjectDto subjectDto){
        return ApiResult.success(subjectService.getDirectoryInfo(subjectDto));
    }

    @PostMapping("getQuestionsList")
    @ApiOperation("课程下的试题列表")
    public ApiResult<ChapterQuestionVo> getQuestionsList(@RequestBody SubjectDto subjectDto){
        return ApiResult.success(subjectService.getQuestionsList(subjectDto));
    }

    @PostMapping("getCoursewareInfo")
    @ApiOperation("当前用户点击课件学习详情")
    public ApiResult<ChapterCoursewareVo> getCoursewareInfo(@RequestBody CoursewareDTO coursewareDTO){
        return ApiResult.success(subjectService.getCoursewareInfo(coursewareDTO));
    }

    @PostMapping("getCoursewareList")
    @ApiOperation("课件学习页面对应的课件列表")
    public ApiResult<SChapterCoursewareVo> getCoursewareList(@RequestBody CoursewareDTO coursewareDTO){
        return ApiResult.success(subjectService.getCoursewareList(coursewareDTO));
    }

    @PostMapping("saveCourseware")
    @ApiOperation("保存课件学习的情况")
    public ApiResult<Boolean> saveCourseware(@Validated({StudyCoursewareDto.Add.class})@RequestBody StudyCoursewareDto studyCoursewareDto){
        return ApiResult.success(subjectService.saveCourseware(studyCoursewareDto));
    }

    @PostMapping("getCommentList")
    @ApiOperation("课程评价列表")
    public ApiResult<Page<EvaluationVo>> getCommentList(@RequestBody SubjectListPageDto subjectListPageDto){
        return ApiResult.success(subjectService.getCommentList(subjectListPageDto));
    }

    @PostMapping("saveComment")
    @ApiOperation("保存评论")
    public ApiResult<Boolean> saveComment(@RequestBody EvaluationDto evaluationDto){
        return ApiResult.success(subjectService.saveComment(evaluationDto));
    }

    @PostMapping("saveReply")
    @ApiOperation("保存回复")
    public ApiResult<Boolean> saveReply(@RequestBody EvaluationDto evaluationDto){
        return ApiResult.success(subjectService.saveReply(evaluationDto));
    }

    @PostMapping("getLike")
    @ApiOperation("查询对课程是否点赞")
    public ApiResult<Boolean> getLike(@RequestBody SubjectDto subjectDto){
        return ApiResult.success(subjectService.getLike(subjectDto));
    }




}
